<?php
/**
 * Zym Framework Demo
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @copyright  Copyright (c) 2008 Zym. (http://www.zym-project.com/)
 * @license http://www.zym-project.com/license New BSD License
 */

/**
 * @see Zend_Form
 */
require_once 'Zend/Form.php';

/**
 * @author Geoffrey Tran
 * @license http://www.zym-project.com/license New BSD License
 * @copyright  Copyright (c) 2008 Zym. (http://www.zym-project.com/)
 */
class Default_Form_Logs_Search extends Zend_Form
{
    /**
     * Initialize form (used by extending classes)
     *
     * @return void
     */
    public function init()
    {
        $this->setAttribs(array(
            'id' => 'search'
        ));

        $this->setMethod('GET');

        $searchField = new Zend_Form_Element_Text('query');
        $searchField->setRequired(true)
                    ->addValidators(array(
                        'notEmpty'
                    ))
                    ->addFilters(array(
                        new Zend_Filter_PregReplace('/[^\p{L}\p{N}\s\-\+\[\]\(\)\:\*\?]/u', '') // TODO: Add a pattern that allows only alnum+whitespace and characters used by lucene queries
                    ));

        $submitButton = new Zend_Form_Element_Submit('search');
        $submitButton->setLabel('Search');

        $this->addElements(array(
            $searchField,
            $submitButton
        ));
    }
}